<template>
	<text class="u-link" @tap.stop="openLink" :style="{
		color: color,
		fontSize: fontSize + 'rpx',
		borderBottom: underLine ? `1px solid ${lineColor ? lineColor : color}` : 'none',
		paddingBottom: underLine ? '0rpx' : '0'
	}">
		<slot></slot>
	</text>
</template>

<script>
	
	export default {
		name: "u-link",
		props: {
			
			color: {
				type: String,
				default: '#2979ff'
			},
			
			fontSize: {
				type: [String, Number],
				default: 28
			},
			
			underLine: {
				type: Boolean,
				default: false
			},
			
			href: {
				type: String,
				default: ''
			},
			
			mpTips: {
				type: String,
				default: '链接已复制，请在浏览器打开'
			},
			
			lineColor: {
				type: String,
				default: ''
			}
		},
		methods: {
			openLink() {
				// #ifdef APP-PLUS
				plus.runtime.openURL(this.href)
				// #endif
				// #ifdef H5
				window.open(this.href)
				// #endif
				// #ifdef MP
				uni.setClipboardData({
					data: this.href,
					success: () => {
						uni.hideToast();
						this.$nextTick(() => {
							this.$u.toast(this.mpTips);
						})
					}
				});
				// #endif
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "../../libs/css/style.components.scss";
	
	.u-link {
		line-height: 1;
	}
</style>
